#include <bits/stdc++.h>
using namespace std;

class ListNode{
public:
	ListNode* next;
	int val;
};

class Solution{
public:
	ListNode* removeElements(ListNode* head, int val) {
		ListNode* dummyHead = new ListNode();
		dummyHead->next = head;
		ListNode* temp = dummyHead;
		while(temp->next != NULL){
			if(temp->next->val == val){
				ListNode* deleteNode = temp->next;
				temp->next = temp->next->next;
				delete deleteNode;
			}else{
				temp = temp->next;	
			}
		}
		head = dummyHead->next;
		delete dummyHead;
		return head;
	}
};

class Test{
public:
	ListNode* removeElements(ListNode* head, int val){
		ListNode* dummyHead = new ListNode();
		dummyHead->next = head;
		ListNode* cur = dummyHead;
		while(cur != NULL && cur->next != NULL){
			if(cur->next->val == val){
				ListNode* tmp = cur->next;
				cur->next = cur->next->next;
				delete tmp;
			}else{
				cur = cur->next;
			}
		}
		head = dummyHead->next;
		delete dummyHead;
		return head;
	}
};


int main(){
	
	
	return 0;
}
